package map.coreui.view

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.ImageView
import com.zjw.zy.base.BaseViewGroup
import com.zjw.zy.R
import com.zjw.zy.base.BaseFragment

/**
 * @author ：zhong.jw
 * @date ：Created in 2022/10/24 17:39
 */
class BackView : BaseViewGroup {

    private val back: ImageView by lazy { findViewById(R.id.back_view_back) }
    private var mListener: OnBackListener? = null

    constructor(context: Context) : super(context) {}
    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {}
    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    ) {
    }

    override fun onLayoutId(): Int {
        return R.layout.back_view
    }

    override fun onBindListener() {}
    override fun onBindValue() {}
    override fun onFindView(rootView: View) {}

    /**
     * attachTo # bindListener 两者选其一
     * */
    fun attachTo(fragment: BaseFragment) {
        back.setOnClickListener {
            fragment.onBackClick()
        }
    }

    fun bindListener(listener: OnBackListener) {
        mListener = listener

        back.setOnClickListener {
            mListener?.onClickBack()
        }
    }

    interface OnBackListener {
        fun onClickBack()
    }
}